package com.wuyixu.service.impl;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.wuyixu.dao.UserMapper;
import com.wuyixu.domain.User;
import com.wuyixu.service.UserService;
@Service(interfaceClass=UserService.class)
public class UserServiceImpl implements UserService{
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User regist(User user) {
		// TODO Auto-generated method stub
		User name = userMapper.findByName(user.getName());
		if(name!=null)
		return null;
		//计算密码的密文 加盐
		String md5Hex = DigestUtils.md5Hex(user.getPassword()+user.getName()+"aaa");
		user.setPassword(md5Hex);
		int result=userMapper.add(user);
		if(result<1)
			return null;
		
		return userMapper.findUserById(user.getUid());
	}

	@Override
	public User login(User user) {
		// TODO Auto-generated method stub
		//计算密码的密文 加盐
		String md5Hex = DigestUtils.md5Hex(user.getPassword()+user.getName()+"aaa");
		user.setPassword(md5Hex);
		return userMapper.findUser(user);
	}

	@Override
	public User getUserByName(String name) {
		// TODO Auto-generated method stub
		return userMapper.findByName(name);
	}

}
